package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.entity.activity.*;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.DecorationModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.GeneralActivityRankMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftSouthSeaMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 15:28
 */
@Cmd(code = GameProtocol.S_SEACRAFT_SOUTH_SEA_RECEIVE_UNION_RANK_FROM_CROSS, desc = "海上争霸 南海丝路 领取联盟排行奖励 跨服返回区服 协议")
public class SeacraftSouthSeaReceiveUnionRankFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg crossToGameMsg = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankCrossToGameMsg.parseFrom(packet.getBytes());
        SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankRespMsg.Builder stcMsg = SeacraftSouthSeaProto.SeacraftSouthSeaReceiveUnionRankRespMsg.newBuilder();
        stcMsg.setRet(crossToGameMsg.getRet());
        if(crossToGameMsg.getRet() == 0) {
            ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(crossToGameMsg.getActivityId());
            int gamePlayerEventType = 0;
            ActivityRewardResult activityRewardResult = null;
            if (null != activityInfo) {
                // 领取奖励
                if (activityInfo.getType() == eActivityType.SeacraftActivity.getValue()) {
                    gamePlayerEventType = eGamePlayerEventType.SeacraftSouthSeaUnionRank.getValue();
                    activityRewardResult = player.getModule(ActivityModule.class).receiveSouthSeaUnionRankReward(crossToGameMsg.getActivityId(), gamePlayerEventType, crossToGameMsg.getRank(), crossToGameMsg.getMasterId(), crossToGameMsg.getUnionId());
                } else if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
                    gamePlayerEventType = eGamePlayerEventType.PeakSeacraftUnionRank.getValue();
                    activityRewardResult = player.getModule(ActivityModule.class).receivePeakSeacraftUnionRankReward(crossToGameMsg.getActivityId(), gamePlayerEventType, crossToGameMsg.getRank(), crossToGameMsg.getPosition(), crossToGameMsg.getUnionId());
                } else {
                    return;
                }
            } else {
                return;
            }

            stcMsg.setRet(activityRewardResult.getRet());
            if (activityRewardResult.getRet() == 0) {
                stcMsg.setReward(activityRewardResult.getReward());
            }
        }
        player.sendPacket(ClientProtocol.U_SEACRAFT_SOUTH_SEA_RECEIVE_UNION_RANK, stcMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
